package org.example.studentsystem_back.common;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;

@Getter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CommonResponse<T> {
    private final int status;
    private final String message;
    private  T data;


    private CommonResponse(int status, String message) {
        this.status = status;
        this.message = message;
    }

    private CommonResponse(int status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    @JsonIgnore
    public boolean isSuccess(){
        return this.status == ResponseCode.SUCCESS.getCode();
    }
    /**
     * 默认成功
     */
    public static <T>CommonResponse<T> createForSuccess() {
        return new CommonResponse<>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMessage());
    }

    /**
     * 默认成功带信息
     */
    public static <T>CommonResponse<T> createForSuccessMessage(String message){
        return new CommonResponse<>(ResponseCode.SUCCESS.getCode(), message);
    }

    /**
     * 默认成功带数据
     */
    public static <T>CommonResponse<T> createForSuccess(T data){
        return new CommonResponse<>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMessage(), data);
    }
    /**
     * 默认成功带数据与信息
     */
    public static <T>CommonResponse<T> createForSuccess(String message, T data){
        return new CommonResponse<>(ResponseCode.SUCCESS.getCode(), message, data);
    }

    /**
     * 默认失败
     */
    public static <T>CommonResponse<T> createForError(){
        return new CommonResponse<>(ResponseCode.ERROR.getCode(), ResponseCode.ERROR.getMessage());
    }
    /**
     * 默认失败带信息
     */
    public static <T>CommonResponse<T> createForError(String message){
        return new CommonResponse<>(ResponseCode.ERROR.getCode(), message);
    }
    /**
     * 默认失败带状态码
     */
    public static <T>CommonResponse<T> createForError(int code,String message){
        return new CommonResponse<>(code, message);
    }

}
